
package com.bear.net.httpclient.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.bear.cmcc.NetTestHTTP.NetworkTestApp;

//FUNO FIX OK这个类没有格式化
/**
 * 网络状态工具类
 * 
 * @author yinghui.hong
 */
public class NetwrokAssistant {
    private static ConnectivityManager connectivityManager;

    /**
     * 获取网络访问类型
     * 
     * @return
     */
    public int getNetworkType() {
        int connectionType = ConnectivityManager.TYPE_MOBILE;
        ConnectivityManager connectivityManager = (ConnectivityManager) NetworkTestApp.getApp()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
            if (connectivityManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI) {
                connectionType = ConnectivityManager.TYPE_WIFI;
            }
        }
        return connectionType;
    }

    public static boolean isNetworkAvailable() {
        boolean isAvailable = false;
        if (connectivityManager == null) {
            connectivityManager = (ConnectivityManager) NetworkTestApp.getApp()
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
        }
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
            isAvailable = true;
        }
        return isAvailable;
    }
}
